<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    
    <title>系统用户---${headerTitle }</title>
    <base href="<%=basePath%>/">
	
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
  	<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1";/><!-- IE的渲染模式 -->
  	<meta name="renderer" content="webkit"><!-- 浏览器高速模式 -->	

    <meta name="keywords" content="信帧,teleframe,iparking,I停车,爱停车,blackshadowwalker" />
	<meta name="description" content="信帧,teleframe,iparking,I停车,爱停车,blackshadowwalker" />
	<meta name="author" content="blackshadowwalker" />
    
	<link href="bootstrap/3/css/bootstrap.css" rel="stylesheet"/>
	<link href="index/css/justified-nav.css" rel="stylesheet">
	<link href="index/css/style.css" rel="stylesheet" >

	<script src="scripts/jquery/jquery-1.7.min.js"></script>
	<script src="bootstrap/3/js/bootstrap.min.js"></script>
	<link href="bootstrap/3/css/datepicker.css" rel="stylesheet"/>
	<script src="bootstrap/3/js/bootstrap-datepicker.js"></script>
	
	<script src="scripts/validateForm.js?t=123"></script>
	<link href="css/common.css" rel="stylesheet"/>
	
	<script src="index/js/index.js?" type="text/javascript"></script>
	
	<script type="text/javascript">
		var msg = "${msg}";
		if(msg!="")
			alert(msg);
			
	</script>
	<style>
		body{
			margin-left: 10px;
			margin-top: 7px;
			width:95%;
		}
	</style>
	
  </head>

  <body>
    
	<div>
		<div class="alert-info" style="">
			<a href="${action }?" class="btn btn-warning"> 返回</a>
			<div style="display:inline;margin-left:30px;color:#f00;">
				${msg }
			</div>
		</div >
	</div>
	
	<form class="form-horizontal" id="myform"  action="${action }?method=${method }" method="post" >
		  <div class="form-group">
		    <label class="col-sm-2 control-label"> 用户头像:</label>
		    <div class="col-sm-5">
		      	 <input type="hidden" name="userInfo.photo" value="${userInfo.photo}" style="width:200px;"/>
				<img src="${userInfo.photo }" for="userInfo.photo" alt="用户头像"   default="images/user/default.gif" 
					style="width:120px;height:130px;cursor:pointer;" onClick="chooserPhoto();"/>
				<input type="button" class="btns_mouseout" onClick="chooserPhoto();" alt="选择头像" value="..."/>
		    </div>
		  </div>
		  <div class="form-group">
		    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>用户帐号:</label>
		    <div class="col-sm-5">
		      	<s:if test="flag==1">
		    		<input type="text" class="form-control" value="${userInfo.userName }" placeholder="用户帐号" disabled/>
		    	</s:if>
		      	<s:else>
		      		<input type="text" class="form-control" name="userInfo.userName"  value="${userInfo.userName }" placeholder="用户帐号"
		      		isValidate="true" notEmpty="true"  notSpecial="true"  specialChar="~!@#$%^&*()+ |?"  leng="20" minLeng="6" />
		      	</s:else>
				(登录帐号)(支持字母、数字、下划线，长度6-20)
				<span class=errorMessage >
					<s:property value="errors['userInfo.userCode'][0]" /> 
				</span>
		    </div>
		  </div>
		  <div class="form-group">
		    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>真实姓名：</label>
		    <div class="col-sm-5">
		      	<input type="text" class="form-control"  name="userInfo.realName"  value="${userInfo.realName }"  placeholder="真实姓名"
		      	isValidate="true" notEmpty="true"  notSpecial="true"  specialChar="~!@#$%^&*()+ |?"  leng="20" minLeng="6"  />
				(支持字母、数字、下划线，长度6-20)
				<span class=errorMessage >
					<s:property value="errors['userInfo.userName'][0]" /> 
				</span>
		    </div>
		  </div>
		
	  	<s:if test="flag==1">
    		<s:set name="notEmpty" value="'false'" />
    	</s:if>
    	<s:else>
    		<s:set name="notEmpty" value="'true'" />
    	</s:else>
    	
		  <div class="form-group">
		    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>用户密码:</label>
		    <div class="col-sm-5">
		      	<input type="password" class="form-control"   name="userInfo.userPasswd" value="" placeholder="登录密码" 
		      		isValidate="true" notEmpty="<s:property value="notEmpty" />"  notSpecial="true"  specialChar="~!@#$%^&*()+ |?"  msg="登录密码"   leng="20" minLeng="6"  />
				(支持字母、数字、下划线，长度6-20)
				<span class=errorMessage >
					<s:property value="errors['userInfo.userPasswd'][0]" /> 
				</span>
		    </div>
		  </div>
		   <div class="form-group">
		    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>再次输入密码：</label>
		    <div class="col-sm-5">
		    	
		      	<input type="password" class="form-control" confirmSameValue="userInfo.userPasswd"  value=""  placeholder="再次输入密码" 
		      		isValidate="true" notEmpty="<s:property value="notEmpty" />"  notSpecial="true"  specialChar="~!@#$%^&*()+ |?"  leng="20" minLeng="6" />
		      	 <span class="errorMessage" >
					<s:property value="errors['parkManager.userPasswd'][0]" />
				</span>
				(支持字母、数字、下划线，长度6-20)
		    </div>
		  </div>
		  
		  <div class="form-group">
		    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>用户角色:</label>
		    <div class="col-sm-5">
		      	 <select id="userRole" class="form-control"  name="userInfo.role" isValidate="true" notEmpty="true"  msg="至少选择一项" >
					<option value="" selected>...</option>
					<s:iterator value="listRole" id="l">
						<option value="${roleId }">${roleName }</option>
					</s:iterator>
				</select>
		    </div>
		  </div>
		   <div class="form-group">
		    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>电子邮箱：</label>
		    <div class="col-sm-5">
				<input type="text" class="form-control" name="userInfo.email" value="${userInfo.email }"  placeholder="电子邮箱"
					isValidate="true"  isEmail="true"  />
		      	 
		    </div>
		  </div>
		   <div class="form-group">
		    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>手机号：</label>
		    <div class="col-sm-5">
				<input type="text" class="form-control" name="userInfo.phone" value="${userInfo.phone }"  placeholder="手机号" 
					isValidate="true" isMobile="true" /> 	
		    </div>
		  </div>
		  <div class="form-group">
		    <label   class="col-sm-2 control-label"><span style="color:#f00">*</span>用户状态：</label>
		    <div class="col-sm-5">
				<select  class=form-control  name="userInfo.status" >
					<option value="1" selected>正常</option>
					<option value="0">锁定</option>
				</select>
		    </div>
		  </div>
		  <div class="form-group">
		    <label for="inputEmail3" class="col-sm-2 control-label"> </label>
		    <div class="col-sm-5">
	    			<input class="btn btn-success btn-lg btn-block"  type=submit value="${headerTitle }"   />
					<input class="btn btn-primary btn-lg btn-block"  type="reset" value="重置"  />
		     </div>
		  </div>
	</form>

	
	<div style="display:none;" id="uploaddiv">
		<form action="UploadAction?callback=uploadcallback"  method="post" ENCTYPE="multipart/form-data" target="hidden_frame" >
			<input type=file name=file onchange="uploadPhoto(this);" />
			<input type="text" name="dir"  value="user/photos" /><br>
		</form>
		<iframe name="hidden_frame"></iframe>
	</div>	
	
	
  </body>
  <script type="text/javascript">
  
  		$("#userRole").val("${userInfo.role}");
		$("select[name='userInfo.status']").val("${userInfo.status}");
		
		$(document).ready(function(){
			$("#myform input[type='submit']").click(function(e){
			    e.preventDefault();//阻止提交按钮的默认 action
			//	  alert("Submit prevented");
				if(!$("#myform").validateForm()){
					return ;
				}
				$("#myform").submit();
			});
		});
			
		
  		function uploadPhoto(obj){
  			$(obj).parent().submit();
  		}
  		
  		function uploadcallback(json){
  			if(window.console)
  				console.log(json);
  			 
			if(json.error==0 || json.error==-2){
				if(json.data.length>=1)
				{
					if(json.data[0].error==0){
						$("input[name='userInfo.photo']").val(json.data[0].path);
						$("img[for='userInfo.photo']").attr("src",json.data[0].path);
					}else{
						alert("上传失败["+json.data[0].msg+"]");
					}
				}else{
					alert("上传失败");
				}
			}else{
				alert(json.msg);
			}
		}
  		
  		function chooserPhoto(){
  			$("#uploaddiv input[name=file]").click();
  		}
  		
  </script>
</html>
